cc.Class({
    extends: cc.Component,

    properties: {
        
    },

    // use this for initialization
    onLoad: function () {
        var self = this;
        var number_node = cc.find("number_bg", this.node);
        number_node.scale = 0;
        number_node.runAction(cc.scaleTo(0.3, 1, 1));
        
        //屏蔽底部点击事件
        cc.find('mask', this.node).on(cc.Node.EventType.TOUCH_START, function (event) {});
        
        //设置按钮事件
        for (let i = 0; i < 10; i++) {
            var numbers = cc.find("number_bg/Number" + i, this.node);
            numbers.on(cc.Node.EventType.TOUCH_END, function() {
                self.onNumberCallfun(i);
            });
        }
        
        for (let i = 0; i < 6; i++) {
            var edit_box = cc.find("number_bg/Edit_box/label_" + i, this.node);
            edit_box.active = false;
        }
    },

    //点击关闭执行动作
    onCloseCallfun: function () {
        var number_node = cc.find("number_bg", this.node);
        number_node.runAction(cc.sequence(
            cc.scaleTo(0.3, 0, 0), 
            cc.callFunc(this.exitThisNode, this)
            ));
    },
    
    //删除当前节点
    exitThisNode: function () {
        this.node.destroy();
    },
    
    //点击数字键
    onNumberCallfun: function (index) {
        var count = 0;
        for (let i = 0; i < 6; i++) {
            var edit_box = cc.find("number_bg/Edit_box/label_" + i, this.node);
            count++;
            if (!edit_box.active) {
                edit_box.getComponent(cc.Sprite).spriteFrame = cc.spriteFrameCache.getSpriteFrame("" + index);
                edit_box.active = true;
                if (count === 6) {
                    cc.director.loadScene("game_scene", function (err, scene) {
                        if (err) {
                            cc.warn("load game_scene err");
                        }
                    });
                } else {
                    return;
                }
            } 
        }
    },
    
    //点击重新输入
    onRemoveCallfun: function () {
        for (let i = 0; i < 6; i++) {
            var edit_box = cc.find("number_bg/Edit_box/label_" + i, this.node);
                edit_box.active = false;
        }
    },
    
    //点击返回
    onDeleteCallfun: function () {
        for (let i = 5; i >= 0; i--) {
            var edit_box = cc.find("number_bg/Edit_box/label_" + i, this.node);
            if (edit_box.active) {
                edit_box.active = false;
                return;
            }
        }
    },
});
